package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.DriverOilSonCard;
import com.egao.orderB.service.DriverOilSonCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 油卡
 * @author : Doman
 * @date : 2021-07-07 16:54:58
 * @version ：1.0
 */
@Api(tags = "油卡子卡")
@RestController
@RequestMapping("/api/orderB/driverOilSonCard")
public class DriverOilSonCardController extends BaseController {

	@Autowired
	private DriverOilSonCardService driverOilSonCardService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:driverOil:list')")
    @ApiOperation(value ="分页查询油卡",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "mainCardId: 主卡id\n" +
        "driverId:司机id\n" +
        "driver:司机姓名\n" +
        "carNo:车牌\n" +
        "oilCard:油卡号\n" +
        "price:余额\n" +
        "oil:油量\n" +
        "remark:备注\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, DriverOilSonCard driverOilSonCard) throws Exception{
        return driverOilSonCardService.list(page, driverOilSonCard, getLoginUser());
    }

    /**
     * 查询全部油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "查询全部")
    @ApiOperation("查询全部油卡")
    @PostMapping("/listAll")
    public JsonResult list(DriverOilSonCard driverOilSonCard){
        return driverOilSonCardService.list(driverOilSonCard, getLoginUser());
    }

    /**
     * 根据id查询油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "根据id查询")
    @ApiOperation("根据id查询油卡")
    @PostMapping("/get")
    public JsonResult get(DriverOilSonCard driverOilSonCard) {
        return driverOilSonCardService.getById(driverOilSonCard);
		// 使用关联查询
        //PageParam<driverOilSonCard> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<driverOilSonCard> records = driverOilSonCardService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:save')")
    @OperLog(value = "油卡", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加油卡",notes = "" +
            "mainCardId: 主卡id\n" +
            "driverId:司机id\n" +
            "driver:司机姓名\n" +
            "carNo:车牌\n" +
            "oilCard:油卡号\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, DriverOilSonCard driverOilSonCard) {
        return driverOilSonCardService.save(driverOilSonCard, getLoginUser());
    }

    /**
     * 修改油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:update')")
    @OperLog(value = "油卡", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改油卡",notes = "" +
            "id:id\n" +
            "driverId:司机id\n" +
            "driver:司机姓名\n" +
            "carNo:车牌\n" +
            "oilCard:油卡号\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, DriverOilSonCard driverOilSonCard) {
        return driverOilSonCardService.update(driverOilSonCard, getLoginUser());
    }

    /**
     * 修改油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:update')")
    @OperLog(value = "油卡分配", desc = "修改", param = false, result = true)
    @ApiOperation(value ="油卡分配",notes = "" +
            "id:id\n" +
            "mainCardId: 主卡id\n" +
            "price:余额\n" +
            "oil:油量\n" +
            "reDate  时间\n" +
        "",httpMethod = "POST")
    @PostMapping("/distribution")
    public JsonResult distribution(Model model, DriverOilSonCard driverOilSonCard) {
        return driverOilSonCardService.distribution(driverOilSonCard, getLoginUser());
    }

    /**
     * 修改油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:update')")
    @OperLog(value = "油卡扣款", desc = "修改", param = false, result = true)
    @ApiOperation(value ="油卡扣款",notes = "" +
            "id:id\n" +
            "mainCardId: 主卡id\n" +
            "price:余额\n" +
            "oil:油量\n" +
            "reDate  时间\n" +
        "",httpMethod = "POST")
    @PostMapping("/deduction")
    public JsonResult deduction(Model model, DriverOilSonCard driverOilSonCard) {
        return driverOilSonCardService.deduction(driverOilSonCard, getLoginUser());
    }

    /**
     * 删除油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:remove')")
    @OperLog(value = "油卡", desc = "删除", result = true)
    @ApiOperation("删除油卡")
    @PostMapping("/remove")
    public JsonResult remove(DriverOilSonCard driverOilSonCard ) {
        return driverOilSonCardService.remove(driverOilSonCard, getLoginUser());
    }

    /**
     * 批量添加油卡
     */
    /**@RequiresPermissions("orderB:driverOil:save")
    @OperLog(value = "油卡", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<DriverOilSonCard> list) {
        if (driverOilSonCardService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改油卡
     */
    /**@RequiresPermissions("orderB:driverOil:update")
    @OperLog(value = "油卡", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<DriverOilSonCard> batchParam) {
        if (batchParam.update(driverOilSonCardService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除油卡
     */
    /**@RequiresPermissions("orderB:driverOil:remove")
    @OperLog(value = "油卡", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (driverOilSonCardService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
